//
//  BaseTableView.m
//  HTP
//
//  Created by admin on 15/10/26.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "BaseTableView.h"
#define TableWidth self.frame.size.width
#define TableHeight  self.frame.size.height
@implementation BaseTableView
-(instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style withHeadRefresh:(BOOL)isHead andFoodRefresh:(BOOL)isFoot{
    self = [super initWithFrame:frame style:style];
    if (self) {
        if (isHead) {
            MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headRefresh)];
            [header setTitle:@"" forState:MJRefreshStateRefreshing];
            [header setTitle:@"" forState:MJRefreshStatePulling];
            [header setTitle:@"" forState:MJRefreshStateIdle];
            [header setTitle:@"" forState:MJRefreshStateWillRefresh];
            self.header = header;
        }
        if (isFoot) {
            self.footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footRefresh)];
        }
        [self setExtraCellLineHidden];
    }
    return self;
}

//TODO:下拉刷新
-(void)headRefresh{
    if (self.baseTableDelegate) {
        [self.baseTableDelegate headRefresh];
    }
    [self performSelector:@selector(endHeadRefresh) withObject:nil afterDelay:2.0];
}
-(void)endHeadRefresh{
    switch (self.header.state) {
        case MJRefreshStateRefreshing:
            [self.header endRefreshing];
            break;
        default:
            break;
    }
}
//TODO:上拉动作
-(void)footRefresh{
    if (self.baseTableDelegate) {
        [self.baseTableDelegate footRefresh];
    }
    [self performSelector:@selector(endFootRefresh) withObject:nil afterDelay:10.0];
}
-(void)endFootRefresh{
    switch (self.footer.state) {
        case MJRefreshStateRefreshing:
            [self.footer endRefreshing];
            break;
        default:
            break;
    }
}
-(void)reloadData{
    [super reloadData];
//    if (self.dataArray == nil || self.dataArray.count == 0) {
//       
//        UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, TableWidth, TableWidth)];
//        footView.backgroundColor = [UIColor redColor];
//        self.tableFooterView = footView;
//    }
}
- (void)setExtraCellLineHidden{
    
    UIView *view =[ [UIView alloc]init];
    
    view.backgroundColor = [UIColor clearColor];
    
    [self setTableFooterView:view];
    
    [self setTableHeaderView:view];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
